package com.example.je_0309;

import com.example.je_0309.modle.MessageInfo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RequestMapping("/message")
@RestController
public class MessageController {
    private List<MessageInfo> messageInfoList = new ArrayList<>();
    @RequestMapping("/publish")
    public Boolean publish(MessageInfo messageInfo) {
            //1.参数校验
        if(!StringUtils.hasText(messageInfo.getFrom()) || !StringUtils.hasText(messageInfo.getTo())
        || !StringUtils.hasLength(messageInfo.getSay())) {
            return false;
        }
            //2.存储数据
        messageInfoList.add(messageInfo);
        return true;
    }


    //获取获取留言信息
    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageInfoList;
    }
}
